#!/usr/bin/env python2
# coding: utf-8


import unittest
from zstack import Client
from zstack.controller import zone

ADMIN_USERNAME = 'admin'
ADMIN_PASSWORD = 'password'
ZSTACK_API_URL = 'http://192.168.1.115:8080/zstack/api'
IMAGE_UUID = '8fb4cffd2dc142ef9c3204ed32d88656'


class TestZone(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.client = Client(ADMIN_USERNAME, ADMIN_PASSWORD, ZSTACK_API_URL)
        cls.client.login()

    def test_create_query_delete_zone(self):
        # 创建zone
        zo = zone.create_zone(self.client, 'py_name')
        self.assertEqual('py_name', zo['name'])

        # 查询zone
        zos = zone.query_zone(self.client)
        self.assertIn(zo['uuid'], [zo1.get('uuid') for zo1 in zos])

        # 根据uuid查询zone
        zo2 = zone.query_zone_by_uuid(self.client, zo['uuid'])
        self.assertTrue(zo2 is not None)

        # 删除zone
        zone.delete_zone(self.client, zo['uuid'])
        zo3 = zone.query_zone_by_uuid(self.client, zo['uuid'])
        self.assertTrue(zo3 == [])


if __name__ == '__main__':
    unittest.main()
